package view.paneles;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

import framework.Vista;


public abstract class PanelWithBg extends JPanel {
	private static final long serialVersionUID = 8077428029906545705L;
	public static final int LOGIN = 0;
	public static final int SESSION = 1;
	public static final int BANNER = 2;

	Image img;
	String imgSource;
	Vista vistaMadre;
	GridBagLayout layout;
	GridBagConstraints c;

	public PanelWithBg(){ 
	}

	public PanelWithBg(Vista vista, int tipo) {
		this.vistaMadre = vista;
		this.layout = new GridBagLayout();
		this.c = new GridBagConstraints();
		this.setLayout(layout);
		ClassLoader classLoader = PanelWithBg.class.getClassLoader();
		this.changeImgSource(tipo);
		URL url= classLoader.getResource (imgSource);
		this.img = new ImageIcon(url).getImage();
		Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
	}

	@Override
	public void paintComponent(Graphics g) {
		g.drawImage(img, 0, 0, null);
	}

	void changeImgSource (int tipo){
		if (tipo == PanelWithBg.LOGIN){
			this.imgSource = "login.jpg";
		}
		else if (tipo == PanelWithBg.SESSION){
			this.imgSource = "bg.jpg";
		} else
			this.imgSource = "banner.jpg";
	}
}
